package com.demon.auto.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 接口响应数据
 *
 * @version 1.0
 * @author huangrz
 * @date 2025/02/19 11:01
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiResponseModel<T> {

    private final static int CODE_SUCCESS = 200;
    private final static int CODE_UNAUTHORIZED = 401;
    private final static int CODE_ERROR = 500;
    /**
     * 参数校验不通过
     */
    private final static int CODE_PARAM_VALID_ERROR = 1001;

    private int code;
    private String message;
    private T data;

    // private String traceId;

    public static <T> ApiResponseModel<T> ok(String msg, T model) {
        return new ApiResponseModel<>(CODE_SUCCESS, msg, model);
    }

    public static <T> ApiResponseModel<T> ok(String msg) {
        return new ApiResponseModel<>(CODE_SUCCESS, msg, null);
    }

    public static <T> ApiResponseModel<T> error(String msg) {
        return new ApiResponseModel<>(CODE_ERROR, msg, null);
    }

    public static <T> ApiResponseModel<T> error(String msg, T model) {
        return new ApiResponseModel<>(CODE_ERROR, msg, model);
    }

    public static <T> ApiResponseModel<T> unauthorized(String msg) {
        return new ApiResponseModel<>(CODE_UNAUTHORIZED, msg, null);
    }

    public static <T> ApiResponseModel<T> paramError(String msg) {
        return new ApiResponseModel<>(CODE_PARAM_VALID_ERROR, msg, null);
    }

}
